package cn.xiyun.xiyuncc.controller;

import cn.xiyun.xiyuncc.dto.CourseParamDto;
import cn.xiyun.xiyuncc.dto.CourseSearchDto;
import cn.xiyun.xiyuncc.result.JSONResult;
import cn.xiyun.xiyuncc.result.PageList;
import cn.xiyun.xiyuncc.server.ISearchCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/searchCourse")
public class SearchCourseController {
    @Autowired
    private ISearchCourseService searchCourseService;

    /**
     * 保存到es
     * @param courseSearchDto
     * @return
     */
    @RequestMapping("/courseSearchSave")
    public JSONResult courseSearchSave(@RequestBody CourseSearchDto courseSearchDto){
        searchCourseService.courseSearchSave(courseSearchDto);
        return JSONResult.success();
    }

    /**
     * 从es删除
     * @param id
     * @return
     */
    @RequestMapping("/courseSearchDelete")
    public JSONResult courseSearchDelete(@PathVariable("id") Long id){
        searchCourseService.courseSearchDelete(id);
        return JSONResult.success();
    }

    /**
     * 从es删除
     * @param courseParamDto
     * @return
     */
    @RequestMapping("/selectCourseSearch")
    public JSONResult selectCourseSearch(@RequestBody CourseParamDto courseParamDto){
        PageList<CourseSearchDto> courseSearchDtoPageList= searchCourseService.selectCourseSearch(courseParamDto);
        return JSONResult.success(courseSearchDtoPageList);
    }
}
